<%@ page language="java" import="java.util.*,org.bluebee.billiardsbar.dao.*,org.bluebee.billiardsbar.dao.impl.*,org.bluebee.billiardsbar.entity.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'tableinfo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="refresh" content="60">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
<!--
	body {font-family: Arial, Helvetica, sans-serif;
			font-size:12px;color:#666666;background:#fff;
			text-align:center;}
	* {margin:0;padding:0;}
	a {color:#1E7ACE;text-decoration:none; }
	a:hover {color:#000;text-decoration:underline;}
	h3 {font-size:14px;font-weight:bold;}
	pre,p {color:#1E7ACE;margin:4px;}
	input, select,textarea {padding:1px;
							margin:2px;font-size:11px;}
	.buttom{padding:1px 10px;font-size:12px;
			border:1px #1E7ACE solid;background:#D0F0FF;}
	#formwrapper {width:450px;margin:15px auto;
					padding:20px;text-align:left;border:1px solid #A4CDF2;}
	fieldset {padding:10px;margin-top:5px;
			border:1px solid #A4CDF2;background:#fff;}
	fieldset legend {color:#1E7ACE;font-weight:bold;
			padding:3px 20px 3px 20px;border:1px solid #A4CDF2; 
			background:#fff;}
	fieldset label {float:left;width:120px;
			text-align:right;padding:4px;margin:1px;}
	fieldset div {clear:left;margin-bottom:2px;}
	input { width:120px;}
	.enter{ text-align:center;}
	.clear {clear:both;}
	.style1 {
	font-size: 12;
	color: #666666;}
	.style2 {
	font-size: small;
	color: #0099FF;}
	.style3 {
	font-size: 12;
	color: #003366;
	font-weight: bold}
-->
</style>
  </head>
  
  <body>
  <%String tableid=request.getParameter("tableid");
  	IBallDao balldao=new BallDaoImpl();
  	String userid="";
  	BallTable balltable=null;
  	if(!tableid.trim().equals("0")){
  		balltable=balldao.getBallTable(tableid);
  		userid=balltable.getUserId();
  	}
  	
  	 long result=0;
	 int hour=0;
	 int min=0;
	 int sec=0;
	 String time="";
	 String strcost="";
	 double sparcost=0;
	 double othercost=0;
	 double last=0;
	 double tablecost=0;
  	 HashMap<String, Long> timeMap=(HashMap<String, Long>) application.getAttribute("timeMap");
	 HashMap<String, Double> costMap=(HashMap<String, Double>) application.getAttribute("costMap");
  	if(timeMap!=null){
  		
	    long value=0;
	    if(!tableid.trim().equals("0")) {
	    value=timeMap.get(tableid);
	    result=(System.nanoTime()-value)/1000000000;
	    hour=(int) (result/3600);
	    min=(int) ((result%3600)/60);
	    sec=(int) (result%60);
	    }
	    time=hour+":"+min+":"+sec;
	}
	if(costMap!=null){
	    double cost=0;
	    if(!tableid.trim().equals("0"))costMap.get(tableid);
	    if(costMap.get(tableid+"sparcost")!=null){
			if(min>30){
				sparcost=costMap.get(tableid+"sparcost")*(hour+1);
			}else{
				sparcost=costMap.get(tableid+"sparcost")*(hour);
			}
			othercost=cost;
			}else{
				sparcost=cost;
			}
		}
		if(min>30){
	    	tablecost=10*(hour+1);
		}else{
			if(hour==0){
				tablecost=10;
			}else{
				tablecost=10*hour;
			}
		}
	    last=othercost+sparcost+tablecost;
		strcost=last+"元";	
		if(userid==null||userid.trim().equals("0")){ time="0:00:00"; strcost="0";}
   %>
  
   <table width="100%"  border="1" bordercolor="#0066FF" height="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50%">
	<table width="100%"  cellspacing="0" cellpadding="0" height="100%">
      <tr>
        <td width="50%">&nbsp;&nbsp; <span class="style1">
        	<span class="style1">台球桌号：</span>&nbsp;&nbsp;<span class="style3"><%=(balltable!=null?balltable.getTableId().trim():"") %></span><br><br>&nbsp;&nbsp;&nbsp; 
        	<span class="style1">房间号：  </span>&nbsp;&nbsp;<span class="style3"><%=(balltable!=null?balltable.getRoomId().trim():"") %></span><br><br>&nbsp;&nbsp;&nbsp; 
        	<span class="style1">是否使用：</span>&nbsp;&nbsp;<span class="style3"><%=(balltable!=null?(balltable.getUserId().trim().equals("0")?"无人使用":"正在使用"):"") %></span><br><br>&nbsp; &nbsp; 
			<span class="style1">用户号：</span>&nbsp;&nbsp;<span class="style3"><%=(balltable!=null?balltable.getUserId().trim():"")%></span><br><br>&nbsp;&nbsp;&nbsp;&nbsp; 
			<span class="style1">使用时间：</span>&nbsp;&nbsp;<span class="style3" id="usetime" name="usetime"><%=time%></span><br><br>&nbsp;&nbsp;&nbsp; 
			<span class="style1">使用费用：</span>&nbsp;&nbsp;<span class="style3" id="usecost" name="usetime"><%=strcost%></span>    
        </td>
        <td width="50%"><fieldset style="width:80%">
			<legend><span class="style2">操作列表</span></legend>
			<br><br>&nbsp;&nbsp; 
			<a href="main_capability/start.jsp?tableid=<%=(balltable!=null?balltable.getTableId().trim():"")%>" target="rightframe">开 &nbsp;&nbsp; 桌</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
			<a href="main_capability/change.jsp?tableid=<%=(balltable!=null?balltable.getTableId().trim():"")%>" target="rightframe">换 &nbsp; &nbsp; &nbsp; 桌</a> <br><br>&nbsp;&nbsp; 
			<a href="main_capability/end.jsp?tableid=<%=(balltable!=null?balltable.getTableId().trim():"")%>" target="rightframe">结 &nbsp;&nbsp; 账</a>&nbsp;&nbsp;&nbsp; &nbsp;
		    <a href="main_capability/addcost.jsp?tableid=<%=(balltable!=null?balltable.getTableId().trim():"")%>" target="rightframe">添加酒水</a><br>
			<p></p><br>
			</fieldset>
		</td>
      </tr>
    </table>
	</td>
    <td width="50%"><iframe name="rightframe" id="rightframe" src="<%=(balltable!=null?(balltable.getUserId().trim().equals("0")?"main_capability/start.jsp?tableid="+balltable.getTableId().trim():"main_capability/end.jsp?tableid="+balltable.getTableId().trim()):"") %>" width="100%" height="100%" title="rightframe"></iframe></td>
  </tr>
</table>
  </body>
</html>
